package com.ttnet.listeners;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.ttnet.bo.UserBo;
import com.ttnet.model.User;
import com.ttnet.model.enumerations.Role;

public class ApplicationContextListener implements ServletContextListener {

	private static final Logger LOG = Logger.getLogger(ApplicationContextListener.class);

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {

		WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
		UserBo userBo = (UserBo) context.getBean("userBo");

		User userAdmin = userBo.getUserByUserName("isagoksu");
		if (userAdmin == null) {
			User user = new User();
			user.setName("\u0130sa");
			user.setSurname("G\u00F6ksu");
			user.setUsername("isagoksu");
			user.setPassword("!Test12345");
			user.setEmail("nomail@nomail.com.tr");
			user.setRole(Role.ROOT);

			userBo.addUser(user);

		}
	}
}
